package com.ecnu.sei.app.course;

import com.ecnu.sei.app.resources.Classroom;
import com.ecnu.sei.app.resources.Time;
import com.ecnu.sei.app.teacher.ITeacher;
import com.ecnu.sei.app.teacher.Official;
import com.ecnu.sei.app.util.Pair;
import com.ecnu.sei.app.util.Utils.CollegeYear;

public class CompulsoryCourse extends AbstractCourse {

  public CompulsoryCourse(CourseInfo info) {
    super(info);
  }
  
  @Override
  public boolean setResource() { 
    Pair<Time, Classroom> resource = scheduler.getFreeResource(info.getCollegeYear());

    if (resource != null) {
      setResource(resource);
      return true;
    }
    return false; 
  }

  private void setResource(Pair<Time, Classroom> resource) {
    ExamInfo examInfo = info.getExamInfo();
    examInfo.setTime(resource.getFirst())
            .setClassroom(resource.getSecond())
            .setProctorNum(info.getStudentNum() >= 60 ? 3 : 2);
  }

  @Override
  public void setResourcePending() { 
    for (CollegeYear collegeYear : CollegeYear.getList()) {
      Pair<Time, Classroom> resource = scheduler.getFreeResource(collegeYear);
      if (resource != null) {
        setResource(resource);
        break;
      }
    }
  } 
}
